home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / system / calcqf.zip / CALCQF.BAS next >
BASIC Source File  |  1988-06-28  |  6KB  |  206 lines

  1. $EVENT OFF
  2. defint a-z
  3.  
  4. SUB SetRefresh
  5. shared Rate
  6. x=int(Rate/256)
  7. out 67,116
  8. out 65,Rate-x*256
  9. out 65,x
  10. end sub
  11.  
  12. SUB Timing
  13. shared ET&
  14. mtimer
  15. for i=1 to 50
  16.   x=i*2+2
  17.   x$=str$(i)
  18. next i
  19. ET&=mtimer
  20. end sub
  21.  
  22. SUB ShowRate(Rate)
  23. print " (HH=";hex$(int(Rate/256));"  LL=";hex$(Rate-int(Rate/256)*256);")"
  24. end sub
  25.  
  26. SUB ShowHead
  27. cls
  28. print "CalcQF  by Ken Hipple (CIS:74076,2331) and Conrad Smith (76701,107)"
  29. print " V1.0      Mississippi Data Equipment Co."
  30. print "           625C Lakeland East Drive"
  31. print "           Jackson, MS 39208               (601) 932-6332"
  32. print
  33. print "This program calculates and sets the optimum memory refresh rate for your"
  34. print "machine.  It will then create a short .COM file that you can run to quickly"
  35. print "set the refresh rate.  The memory refresh concept is from an article by"
  36. print "Brian Roemmele in the 7/88 issue of PC Magazine.  The .COM file produced"
  37. print "is the same as the QFRESH.COM program from that article.  Please see that"
  38. print "article for a thorough discussion of memory refresh rates."
  39. print
  40. print "NOTE: It is possible that your machine will 'hang' before the point"
  41. print "      CalcQF considers optimum is reached.  This will not harm your"
  42. print "      machine but you will have to re-boot."
  43. print
  44. end sub
  45.  
  46. call ShowHead
  47. ComLine$=ucase$(command$)
  48. if instr(ComLine$,"/S") then WriteFile
  49. Tolerance!=.00001
  50. IRate=16
  51. DspLine=17
  52. if instr(ComLine$,"/I") then
  53.   ComLine$=ComLine$+"/C"
  54.   IRate=0
  55.   while IRate<1
  56.     locate DspLine,1
  57.     input "Enter the increment rate desired: ",IRate
  58.   wend
  59. end if
  60. EstOrig=1
  61. if instr(ComLine$,"/O") then
  62.   EstOrig=0
  63.   ComLine$=ComLine$+"/C"
  64. end if
  65. if instr(ComLine$,"/T") then
  66.   ComLine$=ComLine$+"/C"
  67.   Tolerance!=0
  68.   while Tolerance!<=0
  69.     locate DspLine+1,1
  70.     input "Enter the tolerance desired: ",Tolerance!
  71.   wend
  72. end if
  73. if instr(ComLine$,"/C")=0 then
  74.   locate 24,1
  75.   print "Press any key to continue";
  76.   while inkey$=""
  77.   wend
  78.   cls
  79.   print "Switches:
  80.   print
  81.   print "/C - Calculate the optimum memory refresh rate.  /I, /O and /T imply /C"
  82.   print "/I - change the default Increment rate of 16.  In general, larger values"
  83.   print "     will produce numerically higher optimum rates and smaller values"
  84.   print "     will produce lower ones"
  85.   print "/O - don't estimate the Original refresh rate.
  86.   print "/T - set the Tolerance.  The default value is 0.00001. This determines what"
  87.   print "     rate CalcQF considers optimum.  Larger values (i.e. 0.01) should produce"
  88.   print "     numerically lower optimum rates and smaller values (i.e. 0.000001)"
  89.   print "     should produce higher ones."
  90.   print "/S - Skip the calculation phase and go straight to file creation."
  91.   print
  92.   print "Do not press any keys while this program is running as this can affect"
  93.   print "the calculations.  Some TSRs and device drivers may also affect them."
  94.   print "Because of this you may want (or need) to run CalcQF with nothing loaded"
  95.   print "into memory.  The rate referred to as the original rate is the refresh"
  96.   print "rate in effect when CalcQF was started.  The rate CalcQF says is the best"
  97.   print "rate is really only an approximation but it should be close to the best rate"
  98.   print "for any given application.  At the very least it will provide you a good"
  99.   print "starting point for further experimenting."
  100.   locate 24,1
  101.   print "Press any key to continue";
  102.   while inkey$=""
  103.   wend
  104.   end
  105. end if
  106. delay 2
  107. locate DspLine,1
  108. print spc(79)
  109. print spc(79)
  110. call Timing
  111. call Timing
  112. call Timing
  113. OrigET&=ET&
  114. Rate=5
  115. OrigRate=0
  116. if EstOrig=1 then
  117.   while OrigRate=0
  118.     locate DspLine,1
  119.     print "Estimated original refresh rate=";Rate;
  120.     call SetRefresh
  121.     call Timing
  122.     NewET&=ET&
  123.     if (ET&-OrigET&)/OrigET&<Tolerance!/10 then
  124.       OrigRate=Rate
  125.     else
  126.       x=int(Rate/25)
  127.       if x<1 then x=1
  128.       if x>IRate then x=IRate
  129.       incr Rate,x
  130.     end if
  131.   wend
  132.   call ShowRate(OrigRate)
  133. end if
  134. Rate=18
  135. BestET&=9999999
  136. OldET&=BestET&
  137. call SetRefresh
  138. call Timing
  139. StartET&=ET&
  140. ET&=0
  141. Rate=32
  142.  
  143. TimeIt:
  144. call SetRefresh
  145. call Timing
  146. locate DspLine+1,1
  147. print "Testing refresh rate:";Rate
  148. if BestET&>ET& then
  149.   BestRate=Rate
  150.   BestET&=ET&
  151. end if
  152. Rate=Rate+IRate
  153. if (OldET&-ET&)/OldET&>Tolerance! then
  154.   OldET&=ET&
  155.   goto TimeIt
  156. end if
  157. Rate=BestRate
  158. call SetRefresh
  159. locate DspLine+1,1
  160. print "Best refresh rate is:";BestRate;
  161. call ShowRate(BestRate)
  162. if EstOrig=1 then
  163.   print using "###.#% speed improvement over the original rate."_
  164.     ;(OrigET&-BestET&)/OrigET&*100
  165. end if
  166. print using "###.#% speed improvement over rate=18 (HH=0  LL=12)"_
  167.   ;(StartET&-BestET&)/StartET&*100
  168. WriteFile:
  169. Answer$=""
  170. while Answer$<>"Y" and Answer$<>"N"
  171.   Answer$=""
  172.   locate DspLine+4,1
  173.   print "Do you want to create a .COM file? (Y/N) ";
  174.   while Answer$=""
  175.     Answer$=ucase$(inkey$)
  176.   wend
  177. wend
  178. if Answer$="Y" then
  179.   FileName$=""
  180.   while FileName$=""
  181.     locate DspLine+4,1
  182.     print spc(79);
  183.     locate DspLine+4,1
  184.     input "Enter the desired file name with no extension: (default=QFRESH) "_
  185.       ,FileName$
  186.     if len(FileName$)=0 then FileName$="QFRESH"
  187.     if len(FileName$)>8 then FileName$=""
  188.   wend
  189.   Rate=-1
  190.   while Rate<0 or Rate>65535
  191.     locate DspLine+5,1
  192.     input ;"Refresh rate to use: (0 or ENTER to use calculated rate) ",Rate
  193.   wend
  194.   if Rate>0 then BestRate=Rate
  195.   open FileName$+".COM" as #1 len=1
  196.   field #1,1 as CharOut$
  197.   for i=1 to 14
  198.     read x
  199.     if x=1000 then x=BestRate-int(BestRate/256)*256
  200.     if x=2000 then x=int(BestRate/256)
  201.     lset CharOut$=chr$(x)
  202.     put 1
  203.   next i
  204.   close
  205. end if
  206. data &HB0,&H74,&HE6,&H43,&HB0,1000,&HE6,&H41,&HB0,2000,&HE6,&H41,&HCD,&H20